package sample.traditional.web;

import java.io.Serializable;

public class Result<T> implements Serializable {

	private static final long serialVersionUID = -1586118647101027089L;

	/**
	 * 返回代码
	 */
	private int code = ResultCode.FAILURE;

	/**
	 * 信息
	 */
	private String message;

	/**
	 * 对象
	 */
	private T object;

	/**
	 * 是否成功
	 */
	private boolean success = false;

	public Result() {
	}

	public Result(boolean b, int i, String message, T data) {
		this.success = b;
		this.code = i;
		this.message = message;
		this.object = data;
	}

	public int getCode() {
		return code;
	}

	public void setCode(int code) {
		this.code = code;
		this.success = (code == ResultCode.SUCCESS);
	}

	public String getMessage() {
		return message;
	}

	public void setMessage(String message) {
		this.message = message;
	}

	public T getObject() {
		return object;
	}

	public void setObject(T object) {
		this.object = object;
	}

	public boolean isSuccess() {
		return success;
	}

	public void setSuccess(boolean success) {
		this.success = success;
	}

	public static Result success(Object data) {
		return new Result<Object>(true, 0, null, data);
	}

	public static Result fail(int code, String errorMsg) {
		return new Result<Object>(false, code, errorMsg, null);
	}

}
